//
//  ChanelCollectionReusableView.m
//  CNKICommunity
//
//  Created by wei on 17/3/30.
//  Copyright © 2017年 CNKI. All rights reserved.
//

#import "ChanelCollectionReusableView.h"

@interface ChanelCollectionReusableView()
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *titleSubLabel;



@end

@implementation ChanelCollectionReusableView
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.zPosition = -1;//防止移动动画时遮住标签
        [self setupTheSubView];
    }
    return self;
}
-(void)setupTheSubView
{
    [self addSubview:self.titleLabel];
    [self addSubview:self.titleSubLabel];
    [self addSubview:self.editBtn];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(10.);
        make.bottom.mas_equalTo(self.mas_bottom);
        make.width.mas_equalTo(78.);
        make.height.mas_equalTo(25.);
    }];
    
    [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right).offset(-10.);
        make.bottom.mas_equalTo(self.mas_bottom);
        make.width.mas_equalTo(40.);
        make.height.mas_equalTo(25.);
    }];
    
    [self.titleSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel.mas_right).offset(5.);
        make.bottom.mas_equalTo(self.mas_bottom);
        make.width.mas_equalTo(200.);
        make.height.mas_equalTo(25.);
    }];
}
-(UILabel *)titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = [UIFont systemFontOfSize:18.];
        _titleLabel.textColor = [UIColor blackColor];
    }
    return _titleLabel;
}
-(UILabel *)titleSubLabel
{
    if (!_titleSubLabel)
    {
        _titleSubLabel = [[UILabel alloc]init];
        _titleSubLabel.font = [UIFont systemFontOfSize:13.];
        _titleSubLabel.textColor = [UIColor lightGrayColor];
    }
    return _titleSubLabel;
}
-(UIButton *)editBtn
{
    if (!_editBtn) {
        _editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_editBtn setExclusiveTouch:YES];
        [_editBtn addTarget:self action:@selector(TouchEditBtn:) forControlEvents:UIControlEventTouchUpInside];
        [_editBtn setTitle:@"编辑" forState:UIControlStateNormal];
        [_editBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        _editBtn.titleLabel.font = [UIFont systemFontOfSize:16.];
    }
    return _editBtn;
}
-(void)TouchEditBtn:(UIButton*)sender
{
    //协议
    if ([self.ChanelDelegate respondsToSelector:@selector(editButtonClick:)])
    {
        [self.ChanelDelegate editButtonClick:sender];
    }
}

-(void)setSectionIndex:(NSInteger)sectionIndex
{
    _sectionIndex = sectionIndex;
    if (_sectionIndex == 0)
    {
        self.titleLabel.text = @"我的订阅";
        self.titleSubLabel.text = self.isSelectedManagButton ? @"拖拽可以排序" : @"";
        if (self.isSelectedManagButton)
        {
            [self.editBtn setTitle:@"完成" forState:UIControlStateNormal];
        }
        else
        {
            [self.editBtn setTitle:@"编辑" forState:UIControlStateNormal];
        }

        self.editBtn.hidden = NO;
    }
    if (_sectionIndex == 1)
    {
        self.titleLabel.text = @"订阅推荐";
        self.titleSubLabel.text = self.isSelectedManagButton ? @"点击可添加到常用" : @"";
        self.editBtn.hidden = YES;
    }
}






@end
